package zheezes.socket.impl.gbw;

import java.util.ArrayList;
import java.util.List;

import zheezes.protocol.PacketAnalyzer;
import zheezes.protocol.impl.gbw.GbwMasterAddr;
import zheezes.socket.PostOffice;
import zheezes.util.IntUtil;


public class GbwPostOffice extends PostOffice {
	public GbwPostOffice(String host, int port, String msas,
			PacketAnalyzer packetAnalyzer) {
		List<GbwMasterAddr> list = new ArrayList<GbwMasterAddr>();
		for (String s : msas.split(",")) {
			GbwMasterAddr msa = new GbwMasterAddr((byte) IntUtil
					.parse(s.trim()));
			list.add(msa);
		}
		init(host, port, list, packetAnalyzer);
	}

	public GbwPostOffice(String host, int port, List<GbwMasterAddr> msas,
			PacketAnalyzer packetAnalyzer) {
		init(host, port, msas, packetAnalyzer);
	}

	public void init(String host, int port, List<GbwMasterAddr> msas,
			PacketAnalyzer packetAnalyzer) {
		for (GbwMasterAddr msa : msas) {
			GbwPostman postman = new GbwPostman(msa);
			postman.setHost(host);
			postman.setPort(port);
			postman.setPacketAnalyzer(packetAnalyzer);
			postmen.add(postman);
		}
	}
}
